package com.thirtydays.frame.ui.edittext

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatEditText
import com.blankj.utilcode.util.TimeUtils


/**
 * @author 小垚
 * @创建时间： 2021/4/21
 * @描述：不可点击的Edittext
 **/
class DisableOnclickEditText : AppCompatEditText {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun onSelectionChanged(selStart: Int, selEnd: Int) {
        super.onSelectionChanged(selStart, selEnd)
        this.text?.let {
            this.setSelection(it.length)
        }
    }

    var lastTime = 0L
    override fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                var current = TimeUtils.getNowMills()
                if (current - lastTime < 500) {
                    lastTime = current
                    return true
                }
                lastTime = current
            }
        }
        return super.onTouchEvent(event)
    }
}